﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="OAclient.Common" %>

<script type="text/javascript">

    $(function() {
        $("#searchname_txl").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "/Home/SearchTxlFormMy",  //要查询的Action
                    type: "POST",  //Post提交
                    dataType: "json", //json格式数据，默认是text
                    data: { keyword: request.term }, //参数，不知道为什么？请指点
                    success: function(data) {
                        response($.map(data, function(item) {
                            return { label: item.text, value: item.value }; //将返回的jsonresult的属性赋值给autocomplete item
                        }))
                    }
                })
            },
           select: function(event, ui) {
                var t=ui.item.label;
                var arr= t.split(' ');
                $('#searchname_txl').val(arr[0]);  
                $('#searchid_txl').val(ui.item.value); 
                return false;
            },
            minLength:'0',
        })
    });
    
    function proRes(ajaxContext) {
        var restag = {};
        try {
            restag = ajaxContext.get_response().get_object();
        } catch (e) {
            alert("程序出现错误，请联系管理员");
            return;  // return if result is not json
        }

        if (restag.res != true) {
            alert(restag.msg);
        }
        else {
            alert("操作成功");
            refreahtable();
        }
    }

    //刷新
    function refreahtable() {
        var txlgroupid = $("#curtxlgroupid").val();
        var txlgrouptype = $("#curtxlgrouptype").val();

        $.ajax({
            type: "GET",
            url: "/Txl/TxlTable",
            data: { txlgroupid: txlgroupid, txlgrouptype: txlgrouptype },
            success: function(data) {
                $("#selftxlmrg_content").html(data);
            }
        })
    }

    function openTxlAdd() {
        var txlgroup_id = $("#curtxlgroupid").val();
        var txlgrouptype = $("#curtxlgrouptype").val();
        $.ajax({
            type: "GET",
            url: "/Txl/TxlAddOrUpdate",
            data: { txl_id: "", txlgroup_id: txlgroup_id, txlgrouptype: txlgrouptype },
            success: function(data) {
                addtab("3-5-3", "添加组员");
                $("#workarea-3-5-3").html(data);
            }
        })
    }
    
    function doReturn(){
        var txlgroupid = $("#curtxlgroupid").val();
        var txlgrouptype = $("#curtxlgrouptype").val();

        $.ajax({
            type: "GET",
            url: "/Txl/TxlGroupTable",
            data: {txlgrouptype: txlgrouptype },
            success: function(data) {
                $("#selftxlmrg_content").html(data);
            }
        })
    }
    
</script>

<div id="txltable" style="margin-top: 20px;">
    <div>
        <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
            <tr>
                <th>
                    名称
                </th>
                <th>
                    手机
                </th>
                <th>
                    邮箱
                </th>
                <th>
                    传真
                </th>
                <th>
                    查看
                </th>
            </tr>
            <%
                System.Data.DataTable dt_txl = ViewData["dt_txl"] as System.Data.DataTable;
                if (dt_txl.Rows == null || dt_txl.Rows.Count == 0)
                {%>
            <tr>
                <td colspan="0" style="text-align: center;">
                    当前无数据！
                </td>
            </tr>
            <%
                }
                else
                {
                    for (int i = 0; i < dt_txl.Rows.Count; i++)
                    {
            %>
            <tr>
                <td>
                    <%=Ajax.ActionLink(dt_txl.Rows[i]["名称"].ToString(),"TxlAddOrUpdate", new { txl_id = dt_txl.Rows[i]["编号"],
                                                                               txlgroup_id = dt_txl.Rows[i]["小组编号"],
                                                                               txlgrouptype = dt_txl.Rows[i]["小组类型"]},
                                 new AjaxOptions { UpdateTargetId= "workarea-3-5-3", OnSuccess = "addtab('3-5-3','详细资料')" })%>
                </td>
                <td>
                    <%=dt_txl.Rows[i]["手机"]%>
                </td>
                <td>
                    <%=dt_txl.Rows[i]["邮箱"]%>
                </td>
                <td>
                    <%=dt_txl.Rows[i]["传真"]%>
                </td>
                <td>
                    <%=Ajax.ActionLink("更多详情", "TxlAddOrUpdate",
                        new { txl_id = dt_txl.Rows[i]["编号"], txlgroup_id = dt_txl.Rows[i]["小组编号"], txlgrouptype = dt_txl.Rows[i]["小组类型"] },
                    new AjaxOptions { UpdateTargetId = "workarea-3-5-3", OnSuccess = "addtab('3-5-3','详细资料')" })%>
                    <%if (dt_txl.Rows[i]["小组类型"] == "我的通讯录")
                      { %>
                    <%=Ajax.ActionLink("删除", "DoTxlDel",
                                              new { txl_id = dt_txl.Rows[i]["编号"] },
                    new AjaxOptions { UpdateTargetId = "tmp", OnSuccess = "proRes" })%>
                    <%} %>
                </td>
            </tr>
            <%
                }
                } %>
        </table>
        <div id="pageLink">
            <%var pageInfo = ViewData["pageInfo"] as PagingInfo; %>
            <%if (pageInfo != null)
              {  %>
            <%=Ajax.PageLinks(pageInfo, index => Url.Action("TxlTable",new
                {
                    page = index,
                    sname = ViewData["sname"],
                    stype = ViewData["stype"],
                }), new AjaxOptions { UpdateTargetId = "selftxlmrg_content" })%>
            <%} %>
        </div>
    </div>
</div>
